<script src="<?php print $url?>js/jquery.ui.datepicker.js"></script>
<div id="main-content">
  <div class="container-fluid">
    <div class="row-fluid">
			<div class="span12">
				<div class="widget-block">
					<div class="widget-head">
						<h5><?php print $title?></h5>
            <div class="widget-control pull-right">
              <a href="#" data-toggle="dropdown" class="btn dropdown-toggle"><i class="icon-cog"></i><b class="caret"></b></a>
              <ul class="dropdown-menu">
                <li><a href="<?php print   site_url("mrp/asset/add-purchase/") ?>"><i class="icon-plus"></i><?php print lang("create_asset_purchase")?></a></li>
              </ul>
            </div>
					</div>
					<div class="widget-content">
            <div class="widget-searchbox">
              <ul>
                <li class="row-counts">Total Post: <span id='total_row_quotation'><?php print $total?></span></li>
              </ul>
            </div>
            <div class="widget-box">
              <?php print $this->form_eksternal->form_open()?>
              <table class="table search">
                <tr>
                  <td><?php print lang("company")?></td>
                  <td><?php print $this->form_eksternal->form_input("s_title", $this->session->userdata("crm_quotation_search_title"))?></td>
                  <td>&nbsp;</td>
                  <td><?php print lang("user")?></td>
                  <td><?php print $this->form_eksternal->form_input("s_up_to", $this->session->userdata("crm_quotation_search_up_to"))?></td>
                </tr>
                <tr>
                  <td><?php print lang("date")?></td>
                  <td>
                    <?php
                    print $this->form_eksternal->form_date("s_date1", $this->session->userdata("crm_quotation_search_date1"), "s_date1", 'style="width: 100px"');
                    print $this->form_eksternal->form_date("s_date2", $this->session->userdata("crm_quotation_search_date2"), "s_date2", 'style="width: 100px"')?>
                  </td>
                  <td>&nbsp;</td>
                  <td><?php print lang("telphone")?></td>
                  <td><?php print $this->form_eksternal->form_input("s_telphone", $this->session->userdata("crm_quotation_search_telphone"))?></td>
                </tr>
                <tr>
                  <td colspan="5">
                    <button class="btn btn-primary" type="submit" name="cari" value="s"><?php print lang("search")?></button>
                    <button class="btn" type="submit" name="clear" value="c"><?php print lang("clear")?></button>
                  </td>
                </tr>
              </table>
                </form>
              <hr />
              <table id="inti-quotation" class="table table-striped">
                <thead>
                  <tr>
                    <th class="sorting" id="title"><a href="javascript:void(0)" onclick="set_sort('B.title')"><?php print lang("title")?></a></th>
                    <th class="sorting" id="telphone"><a href="javascript:void(0)" onclick="set_sort('A.telphone')"><?php print lang("hrm_department")?></a></th>
                    <th class="sorting" id="total"><a href="javascript:void(0)" onclick="set_sort('A.total')"><?php print lang("date")?></a></th>
                    <th class="sorting" id="total"><a href="javascript:void(0)" onclick="set_sort('A.total')"><?php print lang("pic")?></a></th>
                    <th class="sorting" id="total"><a href="javascript:void(0)" onclick="set_sort('A.total')"><?php print lang("status")?></a></th>
                    <th><?php print lang("action")?></th>
                  </tr>
                </thead>
                <tbody id="ajax-body-quotation">
                </tbody>
              </table>
              <input type="text" value="create_date" id="field_simpan" style="display: none" />
              <input type="text" value="desc" id="sort_simpan" style="display: none" />
            </div>
          </div>
				</div>
			</div>
		</div>
  </div>
</div>

<script>
  function del_row_class(tr){
    $("."+tr).remove();
  }
  function add_row_tambahan(table,url,act,param){
    var no = parseInt($('#'+param).val());
    $('#'+param).val(no+1);
    $.post(url,{no:$('#'+param).val(),action:act},function(data){
        $(data).clone(true).insertBefore("#"+table+" #"+act);
    });
  }
  function set_sort(field){
    var fieldid = field.split(".");
//    console.log(fieldid[1]);
    var curr = $("#"+fieldid[1]).attr("class");
    $("th").removeClass();
    $("th").addClass("sorting");
    $("#"+fieldid[1]).removeClass("sorting");
    $("#field_simpan").val(field);
    if(curr == "sorting_asc"){
      $("#"+fieldid[1]).addClass("sorting_desc");
      del_row_class('ajax-quotation');
      add_row_tambahan('inti-quotation','<?php print site_url("mrp/asset/ajax-purchase")?>/'+field+'/desc/'+$('#total_row_quotation').text(),'ajax-body-quotation');
      $("#sort_simpan").val("desc");
    }
    else{
      $("#"+fieldid[1]).addClass("sorting_asc");
      del_row_class('ajax-quotation');
      add_row_tambahan('inti-quotation','<?php print site_url("mrp/asset/ajax-purchase")?>/'+field+'/asc/'+$('#total_row_quotation').text(),'ajax-body-quotation');
      $("#sort_simpan").val("asc");
    }
  }
  
  $(document).ready( function () {
    
    del_row_class('ajax-quotation');
    add_row_tambahan('inti-quotation','<?php print site_url("mrp/asset/ajax-purchase/create_date/DESC")?>/'+$('#total_row_quotation').text(),'ajax-body-quotation');
    $("th").removeClass();
    $("th").addClass("sorting");
    $("#create_date").removeClass("sorting");
    $("#create_date").addClass("sorting_desc");
  });
  function load_quotation(id){
    if(id == undefined){
      id = 0;
    }
    del_row_class('ajax-quotation');
    add_row_tambahan('inti-quotation','<?php print   site_url("mrp/asset/ajax-purchase")?>/'+$('#field_simpan').text()+"/"+$('#sort_simpan').text()+$('#total_row_quotation').text()+'/'+id,'ajax-body-quotation');
    return false;
  }
  
</script>